/*
 * @lc app=leetcode.cn id=69 lang=javascript
 *
 * [69] Sqrt(x)
 */

// @lc code=start
/**
 * @param {number} x
 * @return {number}
 */
var mySqrt = function (x) {
    if (x < 2) {
        return x;
    }

    // √x = x(1/2) = (e(ln(x)))(1/2) = e(1/2 * ln(x))
    const res = Math.floor(Math.pow(Math.E, 0.5 * Math.log(x)));
    const resPlus = res + 1;
    return resPlus * resPlus <= x ? resPlus : res;
};
// @lc code=end
